package com.helmlabs.grouper.forms.model.validator;

import java.util.List;

import com.helmlabs.grouper.forms.model.field.AbstractField;
import com.helmlabs.grouper.forms.model.field.MultiValueAbstractField;

public class RequiredFieldValidator implements FieldValidator {

	private String message = "This is a required field";
	
	
	public String getMessage() {
		return this.message;
	}
	
	public void setMessage(String message){
		this.message = message;
	}

	public boolean isValid(AbstractField field) {
		if (field instanceof MultiValueAbstractField){
			if (field.getValue()!=null && ((List)field.getValue()).size()>0){
				return true;
			} else {
				return false;
			}
		} else {
			if (field.getValue()==null)
				return false;
			if (field.getValue() instanceof String && "".equals(field.getValue())){
				return false;
			}
		}
		return true;
	}

	
	
}
